{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "安装sklearn  \n",
    "前提准备:  \n",
    "    安装numpy+mkl  \n",
    "- 按照numpy+mkl->scipy->sklearn的顺序一步步在cmd下 pip install+包的绝对路径 即可，这回再次import sklearn做测试，发现不会报错说你没有哪个哪个包了（No module named xxx）    \n",
    "  https://www.cnblogs.com/lyr2015/p/7891069.html  \n",
    "  文件下载:https://blog.csdn.net/qq_16725749/article/details/89396438"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "numpy   1.19.5\n",
    "scipy   1.2.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\6\\\\Desktop\\\\objectForPClass'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "os.getcwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import tensorflow as tf\n",
    "# import keras\n",
    "# config = tf.ConfigProto()\n",
    "# config.gpu_optionsw.allow_growth = True\n",
    "# keras.backend.tensorflow_backend.set_session(tf.Session(config=config))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "#!/usr/bin/env python\n",
    "# -*- coding: utf-8 -*-\n",
    "__author__ = 'Seven'\n",
    "import random\n",
    "import numpy as np\n",
    "from sklearn.model_selection import train_test_split\n",
    "from keras.preprocessing.image import ImageDataGenerator\n",
    "from keras.models import Sequential\n",
    "from keras.layers import Dense, Activation, Flatten, Dropout\n",
    "from keras.layers import Conv2D, MaxPool2D\n",
    "from keras.optimizers import SGD\n",
    "from keras.utils import np_utils\n",
    "from keras.models import load_model\n",
    "from keras import backend as K\n",
    "from face_dataset import load_dataset, resize_image, IMAGE_SIZE\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "import os\n",
    "import sys"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2.3.1'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import keras as k\n",
    "k.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Dataset:\n",
    "    def __init__(self, path_name):\n",
    "        # 训练集\n",
    "        self.train_images = None\n",
    "        self.train_labels = None\n",
    "        # 验证集\n",
    "        # self.valid_images = None\n",
    "        # self.valid_labels = None\n",
    "        # 测试集\n",
    "        self.test_images = None\n",
    "        self.test_labels = None\n",
    "        # 数据加载路径\n",
    "        self.path_name = path_name\n",
    "        # 当前库采用的维度顺序\n",
    "        self.input_shape = None\n",
    " \n",
    "    def load(self, img_rows=IMAGE_SIZE, img_cols=IMAGE_SIZE, img_channels=3, nb_classes=2):\n",
    "        # 加载数据集至内存\n",
    "        images, labels = load_dataset(self.path_name)\n",
    "        #train_labels和test_label只有一个标签1\n",
    "        train_images, test_images, train_labels, test_labels = train_test_split(images, labels, test_size=0.3,\n",
    "                                                                                random_state=random.randint(0, 10))\n",
    "\n",
    "        print('训练数据维度:',train_images.shape)#\n",
    "# set_image_dim_ordering(dim_ordering)是用于设置图像的维度顺序的，有2个可选参数：\n",
    "# （1）‘th’：即Theano模式，会把通道维放在第二个位置上。\n",
    "# （2）‘tf’：即TensorFlow模式，会把通道维放在最后的位置上。\n",
    "# 例：100张RGB三通道的16×32（高为16宽为32）彩色图\n",
    "# th模式下的形式是（100, 3, 16, 32）分别是样本维100张图片、通道维3（颜色通道数）、高、宽\n",
    "# tf模式下的形式是（100, 16, 32, 3）\n",
    "\n",
    "#         if K.image_dim_ordering() == 'th':#版本问题报错,修改如下\n",
    "        if K.image_data_format() == 'channels_first':#此处要仔细看一下通道维度位置变化对下面的影响\n",
    "# 该参数是Keras 1.x中的image_dim_ordering，“channels_last”对应原本的“tf”，“channels_first”对应原本的“th”。\n",
    "# 以128x128x128的数据为例，“channels_first”应将数据组织为（3,128,128,128），而“channels_last”应将数据组织为（128,128,128,3）。\n",
    "# 该参数的默认值是~/.keras/keras.json中设置的值，若从未设置过，则为“channels_last”\n",
    "            train_images = train_images.reshape(train_images.shape[0], img_channels, img_rows, img_cols)#(样本,通道.长,宽)\n",
    "            test_images = test_images.reshape(test_images.shape[0], img_channels, img_rows, img_cols)#同上\n",
    "            self.input_shape = (img_channels, img_rows, img_cols)\n",
    "        else:\n",
    "            train_images = train_images.reshape(train_images.shape[0], img_rows, img_cols, img_channels)\n",
    "            test_images = test_images.reshape(test_images.shape[0], img_rows, img_cols, img_channels)\n",
    "            self.input_shape = (img_rows, img_cols, img_channels)\n",
    " \n",
    "            # 输出训练集、测试集的数量\n",
    "            print(train_images.shape[0], 'train samples')\n",
    "            print(test_images.shape[0], 'test samples')\n",
    "            \n",
    "            \n",
    "            \n",
    "            # 我们的模型使用categorical_crossentropy作为损失函数，因此需要根据类别数量nb_classes将\n",
    "            # 类别标签进行one-hot编码使其向量化，在这里我们的类别只有两种，经过转化后标签数据变为二维\n",
    "            train_labels = np_utils.to_categorical(train_labels, nb_classes)\n",
    "            test_labels = np_utils.to_categorical(test_labels, nb_classes)\n",
    "            # 像素数据浮点化以便归一化\n",
    "            train_images = train_images.astype('float32')\n",
    "            test_images = test_images.astype('float32')\n",
    "            # 将其归一化,图像的各像素值归一化到0~1区间\n",
    "            train_images /= 255.0\n",
    "            test_images /= 255.0\n",
    "            self.train_images = train_images\n",
    "            self.test_images = test_images\n",
    "            self.train_labels = train_labels\n",
    "            self.test_labels = test_labels\n",
    " \n",
    "\n",
    " \n",
    " \n",
    " \n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    " \n",
    "# CNN网络模型类\n",
    "class Model:\n",
    "    def __init__(self):\n",
    "        self.model = None\n",
    " \n",
    "    # 建立模型\n",
    "    def build_model(self, dataset, nb_classes=2):\n",
    "        # 构建一个空的网络模型，它是一个线性堆叠模型，各神经网络层会被顺序添加，专业名称为序贯模型或线性堆叠模型\n",
    "        self.model = Sequential()\n",
    " \n",
    "        # 以下代码将顺序添加CNN网络需要的各层，一个add就是一个网络层\n",
    "        self.model.add(Conv2D(32, 3, 3, border_mode='same',\n",
    "                                     input_shape=dataset.input_shape))  #  2维卷积层\n",
    "        self.model.add(Activation('relu'))  #  激活函数层\n",
    " \n",
    "        self.model.add(Conv2D(32, 3, 3))  # 2维卷积层\n",
    "        self.model.add(Activation('relu'))  #  激活函数层\n",
    " \n",
    "        self.model.add(MaxPool2D(pool_size=(2, 2)))  #  池化层\n",
    "        self.model.add(Dropout(0.25))  #  Dropout层\n",
    " \n",
    "        self.model.add(Conv2D(64, 3, 3, border_mode='same'))  #   2维卷积层\n",
    "        self.model.add(Activation('relu'))  #  激活函数层\n",
    " \n",
    "        self.model.add(Conv2D(64, 3, 3))  #  2维卷积层\n",
    "        self.model.add(Activation('relu'))  #  激活函数层\n",
    " \n",
    "        self.model.add(MaxPool2D(pool_size=(2, 2)))  #  池化层\n",
    "        self.model.add(Dropout(0.25))  # Dropout层\n",
    " \n",
    "        self.model.add(Flatten())  #  Flatten层\n",
    "        self.model.add(Dense(512))  #  Dense层,又被称作全连接层\n",
    "        self.model.add(Activation('relu'))  #  激活函数层\n",
    "        self.model.add(Dropout(0.5))  # Dropout层\n",
    "        self.model.add(Dense(nb_classes))  #  Dense层\n",
    "        self.model.add(Activation('softmax'))  #  分类层，输出最终结果\n",
    " \n",
    "        # 输出模型概况\n",
    "        self.model.summary()\n",
    " \n",
    "    # 训练模型\n",
    "    def train(self, dataset, batch_size=20, nb_epoch=100, data_augmentation=True):\n",
    "        sgd = SGD(lr=0.01, decay=1e-6,\n",
    "                  momentum=0.9, nesterov=True)  # 采用SGD+momentum的优化器进行训练，首先生成一个优化器对象\n",
    "        self.model.compile(loss='categorical_crossentropy',\n",
    "                           optimizer=sgd,\n",
    "                           metrics=['accuracy'])  # 完成实际的模型配置工作\n",
    " \n",
    "        # 不使用数据提升，所谓的提升就是从我们提供的训练数据中利用旋转、翻转、加噪声等方法创造新的\n",
    "        # 训练数据，有意识的提升训练数据规模，增加模型训练量\n",
    "        if not data_augmentation:\n",
    "            self.model.fit(dataset.train_images,\n",
    "                           dataset.train_labels,\n",
    "                           batch_size=batch_size,\n",
    "                           nb_epoch=nb_epoch,\n",
    "                           validation_data=(dataset.test_images, dataset.test_labels),\n",
    "                           shuffle=True)\n",
    "        # 使用实时数据提升\n",
    "        else:\n",
    "            # 定义数据生成器用于数据提升，其返回一个生成器对象datagen，datagen每被调用一\n",
    "            # 次其生成一组数据（顺序生成），节省内存，其实就是python的数据生成器\n",
    "            datagen = ImageDataGenerator(\n",
    "                featurewise_center=False,  # 是否使输入数据去中心化（均值为0），\n",
    "                samplewise_center=False,  # 是否使输入数据的每个样本均值为0\n",
    "                featurewise_std_normalization=False,  # 是否数据标准化（输入数据除以数据集的标准差）\n",
    "                samplewise_std_normalization=False,  # 是否将每个样本数据除以自身的标准差\n",
    "                zca_whitening=False,  # 是否对输入数据施以ZCA白化\n",
    "                rotation_range=20,  # 数据提升时图片随机转动的角度(范围为0～180)\n",
    "                width_shift_range=0.2,  # 数据提升时图片水平偏移的幅度（单位为图片宽度的占比，0~1之间的浮点数）\n",
    "                height_shift_range=0.2,  # 同上，只不过这里是垂直\n",
    "                horizontal_flip=True,  # 是否进行随机水平翻转\n",
    "                vertical_flip=False)  # 是否进行随机垂直翻转\n",
    " \n",
    "            # 计算整个训练样本集的数量以用于特征值归一化、ZCA白化等处理\n",
    "            datagen.fit(dataset.train_images)\n",
    " \n",
    "            # 利用生成器开始训练模型\n",
    "            self.model.fit_generator(datagen.flow(dataset.train_images, dataset.train_labels,\n",
    "                                                  batch_size=batch_size),\n",
    "                                     samples_per_epoch=dataset.train_images.shape[0],\n",
    "                                     nb_epoch=nb_epoch,\n",
    "                                     validation_data=(dataset.test_images, dataset.test_labels))\n",
    "        \n",
    "    MODEL_PATH = './mode_h5/face.model.h5'\n",
    "    def save_model(self, file_path=MODEL_PATH):\n",
    "        self.model.save(file_path)\n",
    " \n",
    "    def load_model(self, file_path=MODEL_PATH):\n",
    "        self.model = load_model(file_path)\n",
    " \n",
    "    def evaluate(self, dataset):\n",
    "        score = self.model.evaluate(dataset.test_images, dataset.test_labels, verbose=1)\n",
    "        # print(\"%s: %.2f%%\" % (self.model.metrics_names[1], score[1] * 100))\n",
    "        print(f'{self.model.metrics_names[1]}:{score[1] * 100}%')\n",
    " \n",
    "    # 识别人脸\n",
    "    def face_predict(self, image):\n",
    "        # 依然是根据后端系统确定维度顺序\n",
    "        if K.image_data_format() == 'channels_first' and image.shape != (1, 3, IMAGE_SIZE, IMAGE_SIZE):\n",
    "            image = resize_image(image)  # 尺寸必须与训练集一致都应该是IMAGE_SIZE x IMAGE_SIZE\n",
    "            image = image.reshape((1, 3, IMAGE_SIZE, IMAGE_SIZE))  # 与模型训练不同，这次只是针对1张图片进行预测\n",
    "        elif K.image_data_format() == 'channels_last' and image.shape != (1, IMAGE_SIZE, IMAGE_SIZE, 3):\n",
    "            image = resize_image(image)\n",
    "            image = image.reshape((1, IMAGE_SIZE, IMAGE_SIZE, 3))\n",
    " \n",
    "            # 浮点并归一化\n",
    "        image = image.astype('float32')\n",
    "        image /= 255.0\n",
    " \n",
    "        # 给出输入属于各个类别的概率，我们是二值类别，则该函数会给出输入图像属于0和1的概率各为多少\n",
    "        result = self.model.predict_proba(image)\n",
    "        print('result:', result)\n",
    " \n",
    "        # 给出类别预测：0或者1\n",
    "        result = self.model.predict_classes(image)\n",
    " \n",
    "        # 返回类别预测结果\n",
    "        return result[0]\n",
    " \n",
    " \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练数据维度: (1400, 64, 64, 3)\n",
      "1400 train samples\n",
      "600 test samples\n",
      "Model: \"sequential_1\"\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "conv2d_1 (Conv2D)            (None, 64, 64, 32)        896       \n",
      "_________________________________________________________________\n",
      "activation_1 (Activation)    (None, 64, 64, 32)        0         \n",
      "_________________________________________________________________\n",
      "conv2d_2 (Conv2D)            (None, 62, 62, 32)        9248      \n",
      "_________________________________________________________________\n",
      "activation_2 (Activation)    (None, 62, 62, 32)        0         \n",
      "_________________________________________________________________\n",
      "max_pooling2d_1 (MaxPooling2 (None, 31, 31, 32)        0         \n",
      "_________________________________________________________________\n",
      "dropout_1 (Dropout)          (None, 31, 31, 32)        0         \n",
      "_________________________________________________________________\n",
      "conv2d_3 (Conv2D)            (None, 31, 31, 64)        18496     \n",
      "_________________________________________________________________\n",
      "activation_3 (Activation)    (None, 31, 31, 64)        0         \n",
      "_________________________________________________________________\n",
      "conv2d_4 (Conv2D)            (None, 29, 29, 64)        36928     \n",
      "_________________________________________________________________\n",
      "activation_4 (Activation)    (None, 29, 29, 64)        0         \n",
      "_________________________________________________________________\n",
      "max_pooling2d_2 (MaxPooling2 (None, 14, 14, 64)        0         \n",
      "_________________________________________________________________\n",
      "dropout_2 (Dropout)          (None, 14, 14, 64)        0         \n",
      "_________________________________________________________________\n",
      "flatten_1 (Flatten)          (None, 12544)             0         \n",
      "_________________________________________________________________\n",
      "dense_1 (Dense)              (None, 512)               6423040   \n",
      "_________________________________________________________________\n",
      "activation_5 (Activation)    (None, 512)               0         \n",
      "_________________________________________________________________\n",
      "dropout_3 (Dropout)          (None, 512)               0         \n",
      "_________________________________________________________________\n",
      "dense_2 (Dense)              (None, 2)                 1026      \n",
      "_________________________________________________________________\n",
      "activation_6 (Activation)    (None, 2)                 0         \n",
      "=================================================================\n",
      "Total params: 6,489,634\n",
      "Trainable params: 6,489,634\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "Epoch 1/100\n",
      "70/70 [==============================] - 2s 35ms/step - loss: 0.6676 - accuracy: 0.5800 - val_loss: 0.6820 - val_accuracy: 0.4850\n",
      "Epoch 2/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.6725 - accuracy: 0.5893 - val_loss: 0.6803 - val_accuracy: 0.5133\n",
      "Epoch 3/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.5364 - accuracy: 0.7250 - val_loss: 0.3001 - val_accuracy: 0.8800\n",
      "Epoch 4/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.4591 - accuracy: 0.8171 - val_loss: 0.3024 - val_accuracy: 0.8900\n",
      "Epoch 5/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.3254 - accuracy: 0.8700 - val_loss: 0.1761 - val_accuracy: 0.9100\n",
      "Epoch 6/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.2646 - accuracy: 0.9057 - val_loss: 0.1372 - val_accuracy: 0.9267\n",
      "Epoch 7/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.2122 - accuracy: 0.9150 - val_loss: 0.0627 - val_accuracy: 0.9783\n",
      "Epoch 8/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.1589 - accuracy: 0.9379 - val_loss: 0.0351 - val_accuracy: 0.9950\n",
      "Epoch 9/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.1305 - accuracy: 0.9529 - val_loss: 0.0482 - val_accuracy: 0.9817\n",
      "Epoch 10/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0909 - accuracy: 0.9679 - val_loss: 0.0394 - val_accuracy: 0.9900\n",
      "Epoch 11/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0798 - accuracy: 0.9714 - val_loss: 0.0283 - val_accuracy: 0.9933\n",
      "Epoch 12/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0790 - accuracy: 0.9764 - val_loss: 0.0380 - val_accuracy: 0.9900\n",
      "Epoch 13/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0850 - accuracy: 0.9779 - val_loss: 0.0224 - val_accuracy: 0.9967\n",
      "Epoch 14/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0802 - accuracy: 0.9771 - val_loss: 0.0253 - val_accuracy: 0.9967\n",
      "Epoch 15/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0294 - accuracy: 0.9893 - val_loss: 0.0173 - val_accuracy: 0.9983\n",
      "Epoch 16/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0305 - accuracy: 0.9921 - val_loss: 0.0174 - val_accuracy: 0.9983\n",
      "Epoch 17/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.4190 - accuracy: 0.8171 - val_loss: 0.0394 - val_accuracy: 0.9883\n",
      "Epoch 18/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.1593 - accuracy: 0.9636 - val_loss: 0.0399 - val_accuracy: 0.9917\n",
      "Epoch 19/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0688 - accuracy: 0.9786 - val_loss: 0.0469 - val_accuracy: 0.9883\n",
      "Epoch 20/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0514 - accuracy: 0.9814 - val_loss: 0.0266 - val_accuracy: 0.9950\n",
      "Epoch 21/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0317 - accuracy: 0.9929 - val_loss: 0.0117 - val_accuracy: 0.9967\n",
      "Epoch 22/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0342 - accuracy: 0.9900 - val_loss: 0.0189 - val_accuracy: 0.9983\n",
      "Epoch 23/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0197 - accuracy: 0.9929 - val_loss: 0.0150 - val_accuracy: 0.9950\n",
      "Epoch 24/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0604 - accuracy: 0.9857 - val_loss: 0.0169 - val_accuracy: 0.9950\n",
      "Epoch 25/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0446 - accuracy: 0.9864 - val_loss: 0.0274 - val_accuracy: 0.9917\n",
      "Epoch 26/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0414 - accuracy: 0.9857 - val_loss: 0.0086 - val_accuracy: 0.9950\n",
      "Epoch 27/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0251 - accuracy: 0.9936 - val_loss: 0.0168 - val_accuracy: 0.9950\n",
      "Epoch 28/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0256 - accuracy: 0.9900 - val_loss: 0.0072 - val_accuracy: 0.9983\n",
      "Epoch 29/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0282 - accuracy: 0.9914 - val_loss: 0.0210 - val_accuracy: 0.9983\n",
      "Epoch 30/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0442 - accuracy: 0.9843 - val_loss: 0.0071 - val_accuracy: 0.9950\n",
      "Epoch 31/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0213 - accuracy: 0.9950 - val_loss: 0.0031 - val_accuracy: 0.9983\n",
      "Epoch 32/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0158 - accuracy: 0.9943 - val_loss: 0.0045 - val_accuracy: 0.9967\n",
      "Epoch 33/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0193 - accuracy: 0.9929 - val_loss: 0.0061 - val_accuracy: 0.9983\n",
      "Epoch 34/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0265 - accuracy: 0.9900 - val_loss: 0.0073 - val_accuracy: 0.9983\n",
      "Epoch 35/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0196 - accuracy: 0.9929 - val_loss: 0.0141 - val_accuracy: 0.9983\n",
      "Epoch 36/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0290 - accuracy: 0.9900 - val_loss: 0.0257 - val_accuracy: 0.9950\n",
      "Epoch 37/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0177 - accuracy: 0.9921 - val_loss: 0.0079 - val_accuracy: 0.9950\n",
      "Epoch 38/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0296 - accuracy: 0.9929 - val_loss: 0.0081 - val_accuracy: 0.9983\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 39/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0118 - accuracy: 0.9964 - val_loss: 0.0269 - val_accuracy: 0.9933\n",
      "Epoch 40/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0185 - accuracy: 0.9957 - val_loss: 0.0177 - val_accuracy: 0.9967\n",
      "Epoch 41/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0123 - accuracy: 0.9957 - val_loss: 0.0147 - val_accuracy: 0.9983\n",
      "Epoch 42/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0228 - accuracy: 0.9921 - val_loss: 0.0062 - val_accuracy: 0.9967\n",
      "Epoch 43/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0116 - accuracy: 0.9957 - val_loss: 0.0076 - val_accuracy: 0.9983\n",
      "Epoch 44/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0151 - accuracy: 0.9921 - val_loss: 0.0051 - val_accuracy: 0.9983\n",
      "Epoch 45/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0334 - accuracy: 0.9850 - val_loss: 0.0088 - val_accuracy: 0.9983\n",
      "Epoch 46/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0148 - accuracy: 0.9950 - val_loss: 0.0047 - val_accuracy: 0.9983\n",
      "Epoch 47/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0136 - accuracy: 0.9943 - val_loss: 0.0143 - val_accuracy: 0.9983\n",
      "Epoch 48/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0207 - accuracy: 0.9929 - val_loss: 0.0069 - val_accuracy: 0.9983\n",
      "Epoch 49/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0119 - accuracy: 0.9964 - val_loss: 0.0080 - val_accuracy: 0.9983\n",
      "Epoch 50/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0113 - accuracy: 0.9964 - val_loss: 0.0044 - val_accuracy: 0.9967\n",
      "Epoch 51/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0095 - accuracy: 0.9971 - val_loss: 0.0076 - val_accuracy: 0.9983\n",
      "Epoch 52/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0066 - accuracy: 0.9979 - val_loss: 0.0116 - val_accuracy: 0.9983\n",
      "Epoch 53/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0116 - accuracy: 0.9957 - val_loss: 0.0120 - val_accuracy: 0.9983\n",
      "Epoch 54/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0090 - accuracy: 0.9979 - val_loss: 0.0121 - val_accuracy: 0.9983\n",
      "Epoch 55/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0083 - accuracy: 0.9957 - val_loss: 0.0165 - val_accuracy: 0.9983\n",
      "Epoch 56/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0137 - accuracy: 0.9957 - val_loss: 0.0093 - val_accuracy: 0.9983\n",
      "Epoch 57/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0089 - accuracy: 0.9979 - val_loss: 0.0039 - val_accuracy: 0.9983\n",
      "Epoch 58/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0057 - accuracy: 0.9993 - val_loss: 0.0081 - val_accuracy: 0.9983\n",
      "Epoch 59/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0085 - accuracy: 0.9979 - val_loss: 0.0081 - val_accuracy: 0.9983\n",
      "Epoch 60/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0175 - accuracy: 0.9943 - val_loss: 0.0148 - val_accuracy: 0.9983\n",
      "Epoch 61/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0105 - accuracy: 0.9971 - val_loss: 0.0061 - val_accuracy: 0.9983\n",
      "Epoch 62/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0258 - accuracy: 0.9929 - val_loss: 0.0083 - val_accuracy: 0.9983\n",
      "Epoch 63/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0153 - accuracy: 0.9943 - val_loss: 0.0075 - val_accuracy: 0.9983\n",
      "Epoch 64/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0045 - accuracy: 0.9979 - val_loss: 0.0110 - val_accuracy: 0.9983\n",
      "Epoch 65/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0029 - accuracy: 0.9986 - val_loss: 0.0120 - val_accuracy: 0.9983\n",
      "Epoch 66/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0064 - accuracy: 0.9971 - val_loss: 0.0089 - val_accuracy: 0.9983\n",
      "Epoch 67/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0164 - accuracy: 0.9979 - val_loss: 0.0077 - val_accuracy: 0.9983\n",
      "Epoch 68/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0068 - accuracy: 0.9979 - val_loss: 0.0099 - val_accuracy: 0.9983\n",
      "Epoch 69/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0059 - accuracy: 0.9979 - val_loss: 0.0125 - val_accuracy: 0.9983\n",
      "Epoch 70/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0057 - accuracy: 0.9986 - val_loss: 0.0153 - val_accuracy: 0.9983\n",
      "Epoch 71/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0137 - accuracy: 0.9957 - val_loss: 0.0115 - val_accuracy: 0.9983\n",
      "Epoch 72/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0041 - accuracy: 0.9986 - val_loss: 0.0085 - val_accuracy: 0.9983\n",
      "Epoch 73/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0016 - accuracy: 1.0000 - val_loss: 0.0097 - val_accuracy: 0.9983\n",
      "Epoch 74/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0048 - accuracy: 0.9979 - val_loss: 0.0125 - val_accuracy: 0.9983\n",
      "Epoch 75/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0041 - accuracy: 0.9993 - val_loss: 0.0025 - val_accuracy: 1.0000\n",
      "Epoch 76/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0192 - accuracy: 0.9950 - val_loss: 0.0081 - val_accuracy: 0.9983\n",
      "Epoch 77/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0044 - accuracy: 0.9971 - val_loss: 0.0099 - val_accuracy: 0.9983\n",
      "Epoch 78/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0109 - accuracy: 0.9950 - val_loss: 0.0060 - val_accuracy: 0.9967\n",
      "Epoch 79/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0106 - accuracy: 0.9964 - val_loss: 0.0145 - val_accuracy: 0.9983\n",
      "Epoch 80/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0042 - accuracy: 0.9993 - val_loss: 0.0116 - val_accuracy: 0.9983\n",
      "Epoch 81/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0215 - accuracy: 0.9943 - val_loss: 0.0160 - val_accuracy: 0.9983\n",
      "Epoch 82/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0067 - accuracy: 0.9964 - val_loss: 0.0119 - val_accuracy: 0.9983\n",
      "Epoch 83/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0110 - accuracy: 0.9950 - val_loss: 0.0104 - val_accuracy: 0.9983\n",
      "Epoch 84/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0034 - accuracy: 0.9986 - val_loss: 0.0121 - val_accuracy: 0.9983\n",
      "Epoch 85/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0022 - accuracy: 1.0000 - val_loss: 0.0087 - val_accuracy: 0.9983\n",
      "Epoch 86/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0020 - accuracy: 0.9993 - val_loss: 0.0053 - val_accuracy: 0.9983\n",
      "Epoch 87/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0040 - accuracy: 0.9979 - val_loss: 0.0130 - val_accuracy: 0.9983\n",
      "Epoch 88/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0033 - accuracy: 0.9993 - val_loss: 0.0055 - val_accuracy: 0.9983\n",
      "Epoch 89/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0049 - accuracy: 0.9986 - val_loss: 0.0036 - val_accuracy: 0.9983\n",
      "Epoch 90/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0117 - accuracy: 0.9979 - val_loss: 0.0126 - val_accuracy: 0.9983\n",
      "Epoch 91/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0048 - accuracy: 0.9971 - val_loss: 0.0068 - val_accuracy: 0.9983\n",
      "Epoch 92/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0169 - accuracy: 0.9921 - val_loss: 0.0137 - val_accuracy: 0.9983\n",
      "Epoch 93/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0026 - accuracy: 0.9993 - val_loss: 0.0185 - val_accuracy: 0.9983\n",
      "Epoch 94/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0015 - accuracy: 0.9993 - val_loss: 0.0173 - val_accuracy: 0.9983\n",
      "Epoch 95/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0117 - accuracy: 0.9964 - val_loss: 0.0103 - val_accuracy: 0.9983\n",
      "Epoch 96/100\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0218 - accuracy: 0.9936 - val_loss: 0.0026 - val_accuracy: 0.9983\n",
      "Epoch 97/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0120 - accuracy: 0.9964 - val_loss: 9.3779e-04 - val_accuracy: 1.0000\n",
      "Epoch 98/100\n",
      "70/70 [==============================] - 1s 17ms/step - loss: 0.0054 - accuracy: 0.9986 - val_loss: 0.0146 - val_accuracy: 0.9983\n",
      "Epoch 99/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0198 - accuracy: 0.9936 - val_loss: 0.0133 - val_accuracy: 0.9983\n",
      "Epoch 100/100\n",
      "70/70 [==============================] - 1s 16ms/step - loss: 0.0033 - accuracy: 0.9986 - val_loss: 0.0081 - val_accuracy: 0.9983\n"
     ]
    },
    {
     "ename": "OSError",
     "evalue": "Unable to create file (unable to open file: name = './mode_5h/meAndLimodel.h5', errno = 2, error message = 'No such file or directory', flags = 13, o_flags = 302)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mOSError\u001b[0m                                   Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-7-205973c12d93>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     11\u001b[0m     \u001b[1;31m# 测试训练函数的代码\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     12\u001b[0m     \u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtrain\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdataset\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m     \u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msave_model\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile_path\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'./mode_5h/meAndLimodel.h5'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;31m#注意路径是mode_h5不是model_h5\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m<ipython-input-6-22cb186aa42a>\u001b[0m in \u001b[0;36msave_model\u001b[1;34m(self, file_path)\u001b[0m\n\u001b[0;32m     84\u001b[0m     \u001b[0mMODEL_PATH\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'./mode_h5/face.model.h5'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     85\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0msave_model\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfile_path\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mMODEL_PATH\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 86\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msave\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile_path\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     87\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     88\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mload_model\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfile_path\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mMODEL_PATH\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\keras\\engine\\network.py\u001b[0m in \u001b[0;36msave\u001b[1;34m(self, filepath, overwrite, include_optimizer)\u001b[0m\n\u001b[0;32m   1150\u001b[0m             \u001b[1;32mraise\u001b[0m \u001b[0mNotImplementedError\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1151\u001b[0m         \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmodels\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0msave_model\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1152\u001b[1;33m         \u001b[0msave_model\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfilepath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moverwrite\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0minclude_optimizer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1153\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1154\u001b[0m     \u001b[1;33m@\u001b[0m\u001b[0msaving\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mallow_write_to_gcs\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\keras\\engine\\saving.py\u001b[0m in \u001b[0;36msave_wrapper\u001b[1;34m(obj, filepath, overwrite, *args, **kwargs)\u001b[0m\n\u001b[0;32m    447\u001b[0m                 \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtmp_filepath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    448\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 449\u001b[1;33m             \u001b[0msave_function\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfilepath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moverwrite\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    450\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    451\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0msave_wrapper\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\keras\\engine\\saving.py\u001b[0m in \u001b[0;36msave_model\u001b[1;34m(model, filepath, overwrite, include_optimizer)\u001b[0m\n\u001b[0;32m    538\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mproceed\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    539\u001b[0m                 \u001b[1;32mreturn\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 540\u001b[1;33m         \u001b[1;32mwith\u001b[0m \u001b[0mH5Dict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'w'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mh5dict\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    541\u001b[0m             \u001b[0m_serialize_model\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mh5dict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0minclude_optimizer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    542\u001b[0m     \u001b[1;32melif\u001b[0m \u001b[0mhasattr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'write'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mcallable\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\keras\\utils\\io_utils.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, path, mode)\u001b[0m\n\u001b[0;32m    189\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_is_file\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    190\u001b[0m         \u001b[1;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msix\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstring_types\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0m_is_path_instance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 191\u001b[1;33m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mh5py\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mFile\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmode\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    192\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_is_file\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    193\u001b[0m         \u001b[1;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python37\\site-packages\\h5py\\_hl\\files.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, name, mode, driver, libver, userblock_size, swmr, rdcc_nslots, rdcc_nbytes, rdcc_w0, track_order, **kwds)\u001b[0m\n\u001b[0;32m    406\u001b[0m                 fid = make_fid(name, mode, userblock_size,\n\u001b[0;32m    407\u001b[0m                                \u001b[0mfapl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfcpl\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmake_fcpl\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtrack_order\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtrack_order\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 408\u001b[1;33m                                swmr=swmr)\n\u001b[0m\u001b[0;32m    409\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    410\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlibver\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtuple\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python37\\site-packages\\h5py\\_hl\\files.py\u001b[0m in \u001b[0;36mmake_fid\u001b[1;34m(name, mode, userblock_size, fapl, fcpl, swmr)\u001b[0m\n\u001b[0;32m    177\u001b[0m         \u001b[0mfid\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mh5f\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mh5f\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mACC_EXCL\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfapl\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfapl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfcpl\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfcpl\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    178\u001b[0m     \u001b[1;32melif\u001b[0m \u001b[0mmode\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'w'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 179\u001b[1;33m         \u001b[0mfid\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mh5f\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mh5f\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mACC_TRUNC\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfapl\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfapl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfcpl\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfcpl\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    180\u001b[0m     \u001b[1;32melif\u001b[0m \u001b[0mmode\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'a'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    181\u001b[0m         \u001b[1;31m# Open in append mode (read/write).\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mh5py\\_objects.pyx\u001b[0m in \u001b[0;36mh5py._objects.with_phil.wrapper\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mh5py\\_objects.pyx\u001b[0m in \u001b[0;36mh5py._objects.with_phil.wrapper\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mh5py\\h5f.pyx\u001b[0m in \u001b[0;36mh5py.h5f.create\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mOSError\u001b[0m: Unable to create file (unable to open file: name = './mode_5h/meAndLimodel.h5', errno = 2, error message = 'No such file or directory', flags = 13, o_flags = 302)"
     ]
    }
   ],
   "source": [
    "if __name__ == '__main__':\n",
    "#     dataset = Dataset('./data/')\n",
    "#     dataset = Dataset(r'./face_serve/')\n",
    "    dataset = Dataset(os.getcwd())\n",
    "\n",
    "    dataset.load()\n",
    " \n",
    "    # 训练模型，这段代码不用，注释掉\n",
    "    model = Model()\n",
    "    model.build_model(dataset)\n",
    "    # 测试训练函数的代码\n",
    "    model.train(dataset)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.save_model(file_path='./mode_h5/meAndLimodel.h5')#注意路径是mode_h5不是model_h5\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# # 评估模型\n",
    "# model = Model()\n",
    "# # model.load_model(file_path='./model/me.face.model.h5')\n",
    "# model.load_model(r\"C:\\Users\\6\\Desktop\\objectForPClass\\mode_h5\\me.face.model.h5\")\n",
    "# model.evaluate(dataset)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# test_images.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# model.face_predict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# model.save_model(file_path='./mode_h5/me.face.model.h5')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
